

#ifndef WRITEBUFFER
#define WRITEBUFFER

#include <pthread.h>

#include <deque>
#include <utility>
#include <string>


class WriteQueue
{
public:
    static WriteQueue * self();

    int submitMessage( pthread_t thread, const std::string & message );
    bool hasMessageWaiting() const;
    std::string currentMessage() const;
    void doneWithMessage( int result );

private:
    static WriteQueue * instance;

    WriteQueue();
    bool containsThread( pthread_t thread ) const;

    int m_lastResult;
    int m_retries;
    mutable pthread_mutex_t m_mutex;
    pthread_cond_t m_cond;
    std::deque<std::pair<pthread_t,std::string> > m_queue;
};


#endif